//
//  ASListControllerDemo.swift
//  soapp_Example
//
//  Created by zhu xietong on 2018/2/13.
//  Copyright © 2018年 CocoaPods. All rights reserved.
//

import Foundation
import soapp
import AsyncDisplayKit
import Eelay
class PPKit: JoTouchNode {
    let imgV = JoImageNode()
    override func addLayoutRules() {
//        flexRules = [
//            [[imgV,_shrink(1),_grow(1)]]
//        ]
    }
    
    override func mo_model_reload() {
        imgV.img_url = mo.model["img",""]
        backgroundColor = UIColor(shex:mo.model["hex",""])
    }
}






class ASListControllerDemo: ASListController {
    let sections:TP.section = [
        [
            [
                "list":[
                    ["img":__images.one_str,"name":__names.one_str],
                ],
            ],            
        ]
    ]
    let selector:TP.selector = [
        "<section1,section0>":Cell.self,

//        "__section0__":JoStaticNodeCell<PPKit,JoDemoNodeLay>.self,
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableNode.load(sections: sections, selector: selector)
    }
 
    override func touch(cell: Any, actionID: String, model: NSMutableDictionary) {
        print("====actionID=|\(actionID)==|\(model)")
    }
    
    deinit {
//        self.tableNode.cle
    }
}

extension ASListControllerDemo{
    
    
    
    class Kit: JoTouchNode {
        
        let imgV = JoImageNode()
        let titleL = ASTextNode()

        override func addLayoutRules() {
            _ = self["100",120]

//            flexRules = [
//                _padding(TP.separatorHeight/2.0),
//                [
//                    imgV["50",50]
//                ],
//            ]
        }
        
        override func mo_model_reload() {
            imgV.img_url = mo.model["img",""]
        }
    }
    
    class Cell: JoCellNode {
        
        let imgV = JoImageNode()
        override func addLayoutRules() {
            
        }
        
        override func mo_model_reload() {
            imgV.img_url = mo.model["list.0.img",""]

        }
    }
    
//    class Cell: JoCellNode {
//        let listV = JoRuleNode<Kit>()
//        override func addLayoutRules() {
//            mf.spec = .inset([],[10], child: listV.Spec)
//        }
//
//        override func mo_model_reload() {
//            listV.mo.model = mo.model
//        }
//    }
    
   
}


class ASColListControllerDemo: ASColListController {
    let sections:TP.section = [
        [
            [
                "list":[
                    ["img":__images.one_str,"name":__names.one_str],
                ],
            ],
        ]
    ]
    let selector:TP.selector = [
        "<section1,section0>":Cell.self,
        //        "__section0__":JoStaticNodeCell<PPKit,JoDemoNodeLay>.self,
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        collectionNode.load(sections: sections, selector: selector)
    }
    
    override func touch(cell: Any, actionID: String, model: NSMutableDictionary) {
        print("====actionID=|\(actionID)==|\(model)")
    }

}

extension ASColListControllerDemo{
    
    
    
    class Kit: JoTouchNode {
        
        let imgV = JoImageNode()
        let titleL = ASTextNode()
        
        override func addLayoutRules() {
            _ = self["100",120]
            
            //            flexRules = [
            //                _padding(TP.separatorHeight/2.0),
            //                [
            //                    imgV["50",50]
            //                ],
            //            ]
        }
        
        override func mo_model_reload() {
            imgV.img_url = mo.model["img",""]

        }
    }
    
    class Cell: ASSizeRangeCell {
        
        
        override func sizeRange() -> ASSizeRange {
            return ASSizeRange(min: CGSize(width: Swidth - 40, height: 100), max: CGSize(width: Swidth, height: 300))
        }
        let imgV = JoImageNode()
        override func addLayoutRules() {
            backgroundColor = .red
        }
        
        
        override func specGetter() -> _Spec {
            
            return .stack([[10]], childs: [
                imgV[100,"100"]
                ])
            
        }
        
        override func mo_model_reload() {
            imgV.img_url = mo.model["list.0.img",""]
        }
    }
    
    //    class Cell: JoCellNode {
    //        let listV = JoRuleNode<Kit>()
    //        override func addLayoutRules() {
    //            mf.spec = .inset([],[10], child: listV.Spec)
    //        }
    //
    //        override func mo_model_reload() {
    //            listV.mo.model = mo.model
    //        }
    //    }
    
    
}

